<template>
	<view class="page">
		<u-cell-group>
			<template v-for="(v, k) in leftSides">
				<u-cell-item v-if="!v.hidden" :key="k" :title="v.name" @click="jumpTo(v)">
					<u-badge :count="v.num" :absolute="false" slot="right-icon"></u-badge>
				</u-cell-item>
			</template>
		</u-cell-group>
	</view>
</template>

<script>
export default {
	components: {},
	data: () => ({
		leftSides: [
			{
				name: '今日需联系客户',
				crmType: 'customer',
				infoType: 'todayCustomer',
				num: 0,
				tips: '下次跟进时间为今日的客户',
				hidden: false,
			},
			{
				name: '分配给我的潜在客户',
				crmType: 'leads',
				infoType: 'followLeads',
				num: 0,
				tips: '转移之后未跟进的线索',
				hidden: false,
			},
			{
				name: '分配给我的目标客户',
				crmType: 'customer',
				infoType: 'followCustomer',
				num: 0,
				tips: '转移、领取、分配之后未跟进的客户，默认显示自己负责的客户',
				hidden: false,
			},
			{
				name: '分配给我的售前申请',
				crmType: 'preSales',
				infoType: 'followPreSales',
				num: 0,
				tips: '转移、分配之后未接受的售前申请，默认显示自己负责的售前申请',
				hidden: false,
			},
			{
				name: '待进入公海的客户',
				crmType: 'customer',
				infoType: 'putInPoolRemind',
				num: 0,
				tips: '',
				hidden: false,
			},
			{
				name: '待审核潜在客户',
				crmType: 'leads',
				infoType: 'checkLeads',
				num: 0,
				tips: '',
				hidden: false,
			},
			{
				name: '待审核目标客户',
				crmType: 'customer',
				infoType: 'checkCustomer',
				num: 0,
				tips: '',
				hidden: false,
			},
			{
				name: '待审核商机',
				crmType: 'business',
				infoType: 'checkBusiness',
				num: 0,
				tips: '',
				hidden: false,
			},
			{
				name: '待审核设备清单',
				crmType: 'preSales',
				infoType: 'checkPreSales',
				num: 0,
				tips: '',
				hidden: false,
			},
			{
				name: '待审核报价',
				crmType: 'quotation',
				infoType: 'checkQuotation',
				num: 0,
				tips: '',
				hidden: false,
			},
			{
				name: '待审核合同',
				crmType: 'contract',
				infoType: 'checkContract',
				num: 0,
				tips: '',
				hidden: false,
			},
			{
				name: '待审核回款',
				crmType: 'receivables',
				infoType: 'checkReceivables',
				num: 0,
				tips: '',
				hidden: false,
			},
			{
				name: '待回款提醒',
				crmType: 'receivables_plan',
				infoType: 'remindReceivablesPlan',
				num: 0,
				tips: '',
				hidden: false,
			},
			{
				name: '即将到期的合同',
				crmType: 'contract',
				infoType: 'endContract',
				num: 0,
				tips: '根据“合同到期时间”及设置的“提前提醒天数”提醒',
				hidden: false,
				url: '',
			},
		],
		// 代办事项数量
		nums: {},
	}),
	methods: {
		// 获取代办事项数量
		async getTodoNums() {
			let res = await this.$api.common.getTodoNum();
			if (res.code === 200) {
				this.nums = res.data || {};
				this.initNums();
			}
		},
		// 初始化数量
		initNums() {
			this.leftSides.forEach((item, index) => {
				if (this.nums.hasOwnProperty(item.infoType)) {
					item.num = this.nums[item.infoType] || 0;
					item.hidden = false;
				} else {
					item.hidden = true;
				}
			});
		},
		// 跳转
		jumpTo(row) {
			uni.navigateTo({
				url: '/pages/customerManagement/todoList/subList?crmType=' + row.crmType + '&infoType=' + row.infoType,
			});
			// if (['customer', 'leads'].includes(row.crmType)) {
			// 	uni.navigateTo({
			// 		url: '/pages/customerManagement/todoList/customer?crmType=' + row.crmType + '&infoType=' + row.infoType,
			// 	});
			// } else {
			// 	uni.navigateTo({
			// 		url: '/pages/customerManagement/todoList/' + row.infoType + '?crmType=' + row.crmType + '&infoType=' + row.infoType,
			// 	});
			// }
			// if (row.crmType === 'quotation') {
			// } else {
			// 	uni.showToast({
			// 		icon: 'none',
			// 		title: '正在努力开发...',
			// 	});
			// }
		},
	},
	computed: {},
	watch: {},

	// 周期函数--监听页面加载
	onLoad() {},
	// 周期函数--监听页面初次渲染完成
	onReady() {},
	// 周期函数--监听页面显示
	onShow() {
		this.getTodoNums();
	},
	// 周期函数--监听页面隐藏
	onHide() {},
	// 周期函数--监听页面卸载
	onUnload() {},
	// 页面处理函数--监听用户下拉动作
	async onPullDownRefresh() {
		await this.getTodoNums();
		uni.stopPullDownRefresh();
	},
	// 页面处理函数--监听用户上拉触底
	async onReachBottom() {
		// uni.stopPullDownRefresh();
	},
	// 页面处理函数--监听页面滚动
	/* onPageScroll(event) {}, */
	// 页面处理函数--用户点击右上角分享
	/* onShareAppMessage(options) {}, */
};
</script>

<style></style>
